package cn.roderick.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@EnableTransactionManagement(order=2)
@MapperScan(basePackages = {"cn.roderick.web.dao"})
public class MybatisConfig {

    @Autowired
    DruidProperties druidProperties;

    /**
     * DataSource配置
     */
    @Bean
    public DataSource dataSource() {
        DruidDataSource dataSource=new DruidDataSource();
        druidProperties.config(dataSource);
        return dataSource;
    }

    /**
     * 提供SqlSeesionFactoryBean
     */
   /* @Bean
   public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource());
        return sqlSessionFactoryBean;
    }*/
}
